package com.yuyuan.blog.domain.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.qcloud.cos.http.HttpMethodName;
import com.yuyuan.blog.utils.COSUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.time.LocalDateTime;

/**
 * 陪练帖
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("tb_blog_practice")
@Document(indexName = "practice")
public class BlogPractice{
    /**
     * 主键
     */
    @TableId(value = "id",type = IdType.INPUT)
    @Id
    private Long id;
    /**
     * 用户id
     */
    @Field(type = FieldType.Long)
    private Long userId;
    /**
     * 用户头像
     */
    @Field(type = FieldType.Text)
    private String icon;
    /**
     * 用户名称
     */
    @Field(type = FieldType.Text)
    private String userName;
    /**
     * 培教类型：0：找陪练，1：找教练
     */
    @Field(type = FieldType.Short)
    private Short type;
    /**
     * 需求
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String demand;
    /**
     * 时间
     */
    @Field(type = FieldType.Text)
    private String time;
    /**
     * 地点
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String location;
    /**
     * 价格
     */
    @Field(type = FieldType.Text)
    private String price;
    /**
     * 人数
     */
    @Field(type = FieldType.Text)
    private String people;
    /**
     * 补充内容
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String content;
    /**
     * 联系方式
     */
    @Field(type = FieldType.Text)
    private String contact;
    /**
     * 状态码：0正常，1：被举报，2：禁止查看
     */
    @Field(type = FieldType.Integer)
    private Integer status = 0;
    /**
     * 创建时间
     */
    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "uuuu-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "uuuu-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;
    /**
     * 头像url
     */
    @TableField(exist = false)
    private String iconUrl = "";
    /**
     * 帖子得分
     */
    private int score;
    public void handlerImgs() {
        this.iconUrl = COSUtils.getSign(this.icon, HttpMethodName.GET);
    }
}
